package com.AJava1710D.bingfabao.sympho;

import java.util.concurrent.Semaphore;

/**
 * 作者: LCG
 * 日期: 2020/6/23 11:55
 * 描述:
 */
public class TestRun3 implements Runnable {

    private Semaphore semaphore;

    private long time;

    public TestRun3(Semaphore semaphore, long time) {
        this.semaphore = semaphore;
        this.time = time;
    }

    @Override
    public void run() {

        try {
            //尝试获取资源  如果获取不到的话要阻塞到当前位置
            semaphore.acquire();
            //执行自己的业务操作
            Thread.sleep(time);
            System.out.println("====="+Thread.currentThread().getName());

            //释放资源
            semaphore.release();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
